﻿using furion.blog.Domain.Shared;
using furion.blog.Domain.Shared.Enum;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Domain.Query.Member
{
    public class MemberListQuery : BaseQuery
    {
        public string SearchContent { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty;
        public string IsDelete { get; set; } = YesOrNoEnum.No.ToString();

        /// <summary>
        /// 返回查询where 和 条件参数
        /// </summary>
        /// <returns></returns>
        public (string, List<SugarParameter>) QueryParams()
        {
            List<SugarParameter> parameters = new List<SugarParameter>();
            StringBuilder strWhere = new StringBuilder(" 1=1 ");
            if (!string.IsNullOrWhiteSpace(SearchContent))
            {
                strWhere.AppendLine(" and (t.Phone like @searchContent " +
                    " or t.RealName like @searchContent " +
                    " or t.NickName like @searchContent " +
                    " or t.Email like @searchContent " +
                    ") ");
                parameters.Add(new SugarParameter("searchContent", "%"+ SearchContent + "%"));
            }
            if (!string.IsNullOrWhiteSpace(IsDelete))
            {
                strWhere.AppendLine(" and t.isDelete=@isDelete ");
                parameters.Add(new SugarParameter("isDelete", IsDelete));
            }
            if (!string.IsNullOrWhiteSpace(Status))
            {
                strWhere.AppendLine(" and t.status=@status ");
                parameters.Add(new SugarParameter("status", Status));
            }
            return (strWhere.ToString(), parameters);
        }
    }
}
